﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Drawing.Printing;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Windows.Forms;
namespace GUI.BaoCao
{
    public partial class frmBaoCaorpt : Form
    {
        #region khởi tạo
        bool checkClose = false;
        SaveFileDialog savefile;
        PrintDialog printDialog1;
        PrintDocument printDocument1;
        public bool kiemtra = false;
        Entities.CongTy[] congty;
        string name;
        Object[] obj;
        Object obj1;
        Object obj2;
        DateTime date;
        string tenkho;
        string makho;
        string loaihoadon;
        DateTime tungay;
        DateTime denngay;
        
        public frmBaoCaorpt()
        {
            InitializeComponent();
        }

        #endregion

        #region Print
        public bool Print(CrystalDecisions.CrystalReports.Engine.ReportDocument Chart)
        {
            try
            {
                ReportDocument crReportDocument;
                crReportDocument = new ReportDocument();
                //Create an instance of a report
                crReportDocument = Chart;
                printDialog1 = new System.Windows.Forms.PrintDialog();
                printDocument1 = new PrintDocument();
                //Open the PrintDialog
                this.printDialog1.Document = this.printDocument1;
                System.Windows.Forms.DialogResult dr = this.printDialog1.ShowDialog();
                if (dr == System.Windows.Forms.DialogResult.OK)
                {
                    //Get the Copy times
                    int nCopy = this.printDocument1.PrinterSettings.Copies;
                    //Get the number of Start Page
                    int sPage = this.printDocument1.PrinterSettings.FromPage;
                    //Get the number of End Page
                    int ePage = this.printDocument1.PrinterSettings.ToPage;
                    string PrinterName = this.printDocument1.PrinterSettings.PrinterName;

                    crReportDocument = new ReportDocument();
                    //Create an instance of a report
                    crReportDocument = Chart;
                    try
                    {
                        //Set the printer name to print the report to.  By default the sample
                        //report does not have a defult printer specified.  This will tell the
                        //engine to use the specified printer to print the report.  Print out 
                        //a test page (from Printer properties) to get the correct value.

                        crReportDocument.PrintOptions.PrinterName = PrinterName;


                        //Start the printing process.  Provide details of the print job
                        //using the arguments.
                        crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage);
                        return true;
                    }
                    catch
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            catch
            {
                return false;
            }
        }

        void XuLyIn(ReportDocument report, Entities.CongTy congty)
        {
            try
            {
                report.SetParameterValue("NgayTao", Entitystatic.date.ToString("dd/MM/yyyy"));
            }
            catch
            {
            }
            report.SetParameterValue("TenCongTy", congty.TenCongTy);
            report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
            report.SetParameterValue("DienThoai", congty.DienThoai);
            report.SetParameterValue("FaxCongTy", congty.Fax);
            report.SetParameterValue("Web", congty.Website);
            report.SetParameterValue("Email", congty.Email);
            if (Print(report))
            {
                kiemtra = true;
                rptViewer.ReportSource = report;
                rptViewer.Show();
            }
        }
        #endregion

        #region công ty
        Entities.CongTy CongTy()
        {
            try
            {
                Entities.CongTy ct;
                ct = new Entities.CongTy();
                ct.HanhDong = "0";
                congty = Common.StaticVariable.InterfaceObject.SelectCongTy(ct);
                if (congty == null || congty.Length == 0)
                {
                    ct = new Entities.CongTy();
                    ct.CongTyID = 0;
                    ct.TenCongTy = "";
                    ct.MaCongTy = "";
                    ct.LinkImage = "";
                    ct.Website = "";
                    ct.DiaChi = "";
                    ct.DienThoai = "";
                    ct.Email = "";
                    ct.Fax = "";
                    ct.GhiChu = "";
                    ct.HanhDong = "";
                }
                else
                {
                    ct = congty[0];
                    ct = Common.StaticVariable.InterfaceObject.Select_CongTy(ct);
                }
                return ct;
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region Báo cáo bán hàng theo nhân viên
        public frmBaoCaorpt(Entities.BCDoanhThuTheoNhanVien[] bc, string tenkho, DateTime batdau, DateTime ketthuc)
        {
            InitializeComponent();
            name = "BCDoanhThuTheoNhanVien";
            obj = bc;
            this.tenkho = tenkho;
            this.tungay = batdau;
            this.denngay = ketthuc;
            Entities.CongTy congty = CongTy();
            if (congty.MaCongTy.Length != 0)
                bc[0].LoGo = congty.Image; 
            lblTitle.Text = "Báo Cáo Bán Hàng Theo Nhân Viên";

            GUI.BaoCao.Report.rptBCDoanhThuTheoNhanVien report = new GUI.BaoCao.Report.rptBCDoanhThuTheoNhanVien();
            report.SetDataSource(bc);
            report.SetParameterValue("TenCongTy", congty.TenCongTy);
            report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
            report.SetParameterValue("DienThoai", congty.DienThoai);
            report.SetParameterValue("FaxCongTy", congty.Fax);
            report.SetParameterValue("Web", congty.Website);
            report.SetParameterValue("Email", congty.Email);
            report.SetParameterValue("TenBaoCao", "Báo Cáo Bán Hàng Theo Nhân Viên".ToUpper());
            report.SetParameterValue("KhoHang", tenkho);
            report.SetParameterValue("TuNgay", batdau.ToString("dd/MM/yyyy"));
            report.SetParameterValue("DenNgay", ketthuc.ToString("dd/MM/yyyy"));
            XuLyIn(report, congty);
        }

        public frmBaoCaorpt(Entities.BCDoanhThuTheoNhanVien[] bc, string tenkho, DateTime batdau, DateTime ketthuc, string path, string hanhdong)
        {
            InitializeComponent();
            obj = bc;
            name = "BCDoanhThuTheoNhanVien";
            this.tenkho = tenkho;
            this.tungay = batdau;
            this.denngay = ketthuc;
            try
            {
                XuLy(bc, tenkho, batdau, ketthuc, path, hanhdong);
            }
            catch
            {
            }
        }

        void XuLy(Entities.BCDoanhThuTheoNhanVien[] bc, string tenkho, DateTime batdau, DateTime ketthuc, string path, string hanhdong)
        {
            Entities.CongTy congty = CongTy();
            if (congty.MaCongTy.Length != 0)
                bc[0].LoGo = congty.Image; 
            lblTitle.Text = "Báo Cáo Bán Hàng Theo Nhân Viên";

            GUI.BaoCao.Report.rptBCDoanhThuTheoNhanVien report = new GUI.BaoCao.Report.rptBCDoanhThuTheoNhanVien();
            report.SetDataSource(bc);
            try
            {
                report.SetParameterValue("NgayTao", Entitystatic.date.ToString("dd/MM/yyyy"));
            }
            catch
            {
            }
            report.SetParameterValue("TenCongTy", congty.TenCongTy);
            report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
            report.SetParameterValue("DienThoai", congty.DienThoai);
            report.SetParameterValue("FaxCongTy", congty.Fax);
            report.SetParameterValue("Web", congty.Website);
            report.SetParameterValue("Email", congty.Email);
            report.SetParameterValue("TenBaoCao", "Báo Cáo Bán Hàng Theo Nhân Viên".ToUpper());
            report.SetParameterValue("KhoHang", tenkho);
            report.SetParameterValue("TuNgay", batdau.ToString("dd/MM/yyyy"));
            report.SetParameterValue("DenNgay", ketthuc.ToString("dd/MM/yyyy"));
            if (hanhdong == Common.Constants.Excel)
            {
                new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
            }
            else if (hanhdong == Common.Constants.Word)
            {
                new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
            }
            else if (hanhdong == Common.Constants.PDF)
            {
                new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
            }
        }
        #endregion

        #region Báo cáo bán hàng theo hóa đơn

        public frmBaoCaorpt(Entities.BCBanHangTheoHoaDon[] bc, string tenkho, string loaihoadon, DateTime tungay, DateTime denngay, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCBanHangTheoHoaDon";
            obj = bc;
            this.tenkho = tenkho;
            this.loaihoadon = loaihoadon;
            this.tungay = tungay;
            this.denngay = denngay;
            try
            {
                XuLy(bc, tenkho, loaihoadon, tungay, denngay, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCBanHangTheoHoaDon[] bc, string tenkho, string loaihoadon, DateTime tungay, DateTime denngay, string path, string hanhdong)
        {
            Entities.CongTy congty = CongTy();
            if (congty.MaCongTy.Length != 0)
                bc[0].LoGo = congty.Image; 
            lblTitle.Text = "Báo Cáo Bán Hàng Theo Hóa Đơn";


            GUI.BaoCao.Report.rptBCBanHangTheoHoaDon report = new GUI.BaoCao.Report.rptBCBanHangTheoHoaDon();
            report.SetDataSource(bc);
            try
            {
                report.SetParameterValue("NgayTao", Entitystatic.date.ToString("dd/MM/yyyy"));
            }
            catch
            {
            }
            report.SetParameterValue("TenCongTy", congty.TenCongTy);
            report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
            report.SetParameterValue("DienThoai", congty.DienThoai);
            report.SetParameterValue("FaxCongTy", congty.Fax);
            report.SetParameterValue("Web", congty.Website);
            report.SetParameterValue("Email", congty.Email);
            report.SetParameterValue("TuNgay", tungay.ToString("dd/MM/yyyy"));
            report.SetParameterValue("DenNgay", denngay.ToString("dd/MM/yyyy"));
            report.SetParameterValue("LoaiHoaDon", loaihoadon);
            report.SetParameterValue("TenBaoCao", "Báo Cáo Bán Hàng Theo Hóa Đơn".ToUpper());
            report.SetParameterValue("KhoHang", tenkho);

            if (hanhdong == Common.Constants.Excel)
            {
                new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
            }
            else if (hanhdong == Common.Constants.Word)
            {
                new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
            }
            else if (hanhdong == Common.Constants.PDF)
            {
                new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
            }
        }

        public frmBaoCaorpt(Entities.BCBanHangTheoHoaDon[] bc, string tenkho, string loaihoadon, DateTime tungay, DateTime denngay)
        {
            InitializeComponent();
            name = "BCBanHangTheoHoaDon";
            obj = bc;
            this.tenkho = tenkho;
            this.loaihoadon = loaihoadon;
            this.tungay = tungay;
            this.denngay = denngay;

            Entities.CongTy congty = CongTy();
            if (congty.MaCongTy.Length != 0)
                bc[0].LoGo = congty.Image;
            lblTitle.Text = "Báo Cáo Bán Hàng Theo Hóa Đơn";



            BaoCao.Report.rptBCBanHangTheoHoaDon report = new Report.rptBCBanHangTheoHoaDon();
            report.SetDataSource(bc);
            report.SetParameterValue("TuNgay", tungay.ToString("dd/MM/yyyy"));
            report.SetParameterValue("DenNgay", denngay.ToString("dd/MM/yyyy"));
            report.SetParameterValue("LoaiHoaDon", loaihoadon);
            report.SetParameterValue("TenBaoCao", "Báo Cáo Bán Hàng Theo Hóa Đơn".ToUpper());
            report.SetParameterValue("KhoHang", tenkho);
            XuLyIn(report, congty);
        }
        #endregion

        #region Báo cáo bán hàng theo ngày
        public frmBaoCaorpt(Entities.BCBanHangTheoNgay[] bc, string tenkho, string loaihoadon, double sotienphaithu, double sotiendathu)
        {
            InitializeComponent();
            name = "BCBanHangTheoNgay";
            obj = bc;
            this.tenkho = tenkho;
            this.sotienphaithu = sotienphaithu;
            this.sotiendathu = sotiendathu;
            this.loaihoadon = loaihoadon;
            try
            {
                DateTime date = Entitystatic.date;
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image; 
                lblTitle.Text = "Báo Cáo Bán Hàng Theo Ngày";


                GUI.BaoCao.Report.rptBCBanHangTheoNgay report = new GUI.BaoCao.Report.rptBCBanHangTheoNgay();
                report.SetDataSource(bc);
                report.SetParameterValue("Ngay", date.ToString("dd/MM/yyyy"));
                report.SetParameterValue("TenBaoCao", "Báo Cáo Bán Hàng Theo Ngày".ToUpper());
                report.SetParameterValue("KhoHang", tenkho);
                report.SetParameterValue("LoaiHoaDon", loaihoadon);
                report.SetParameterValue("SoTienPhaiThu", Common.Utilities.FormatMoney(sotienphaithu.ToString()));
                report.SetParameterValue("SoTienDaThu", Common.Utilities.FormatMoney(sotiendathu.ToString()));
                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        double sotienphaithu = 0;

        double sotiendathu = 0;

        public frmBaoCaorpt(Entities.BCBanHangTheoNgay[] bc, string tenkho, string loaihoadon, double sotienphaithu, double sotiendathu, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCBanHangTheoNgay";
            obj = bc;
            this.tenkho = tenkho;
            this.sotienphaithu = sotienphaithu;
            this.sotiendathu = sotiendathu;
            try
            {
                XuLy(bc, tenkho, loaihoadon, sotienphaithu, sotiendathu, path, hanhdong);
            }
            catch
            {
            }
        }

        void XuLy(Entities.BCBanHangTheoNgay[] bc, string tenkho, string loaihoadon, double sotienphaithu, double sotiendathu, string path, string hanhdong)
        {
            try
            {
                DateTime date = Entitystatic.date;
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image; lblTitle.Text = "Báo Cáo Bán Hàng Theo Ngày";


                GUI.BaoCao.Report.rptBCBanHangTheoNgay report = new GUI.BaoCao.Report.rptBCBanHangTheoNgay();
                report.SetDataSource(bc);
                try
                {
                    report.SetParameterValue("NgayTao", date.ToString("dd/MM/yyyy"));
                }
                catch
                {
                }
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);
                report.SetParameterValue("Ngay", date.ToString("dd/MM/yyyy"));
                report.SetParameterValue("TenBaoCao", "Báo Cáo Bán Hàng Theo Ngày".ToUpper());
                report.SetParameterValue("KhoHang", tenkho);
                report.SetParameterValue("LoaiHoaDon", loaihoadon);
                report.SetParameterValue("SoTienPhaiThu", Common.Utilities.FormatMoney(sotienphaithu.ToString()));
                report.SetParameterValue("SoTienDaThu", Common.Utilities.FormatMoney(sotiendathu.ToString()));
                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }
        #endregion

        #region Báo cáo chi tiết bán hàng theo hàng hóa
        public frmBaoCaorpt(Entities.BCChiTietBanHangTheoHangHoa[] bc, string tenkho, string loaihoadon, DateTime tungay, DateTime denngay)
        {
            InitializeComponent();
            name = "BCChiTietBanHangTheoHangHoa";
            obj = bc;
            this.tenkho = tenkho;
            this.tungay = tungay;
            this.denngay = denngay;
            this.loaihoadon = loaihoadon;
            DateTime date = Entitystatic.date;
            Entities.CongTy congty = CongTy();
            if (congty.MaCongTy.Length != 0)
                bc[0].LoGo = congty.Image; 
            lblTitle.Text = "Báo Cáo Chi Tiết Bán Hàng Theo Hàng Hóa";

            GUI.BaoCao.Report.rptBCChiTietBanHangTheoHANGHOA report = new GUI.BaoCao.Report.rptBCChiTietBanHangTheoHANGHOA();
            report.SetDataSource(bc);
            report.SetParameterValue("TenBaoCao", "Báo Cáo Chi Tiết Bán Hàng Theo Hàng Hóa".ToUpper());
            report.SetParameterValue("TenKho", tenkho);
            report.SetParameterValue("LoaiHoaDon", loaihoadon);
            report.SetParameterValue("TuNgay", tungay.ToString("dd/MM/yyyy"));
            report.SetParameterValue("DenNgay", denngay.ToString("dd/MM/yyyy"));

            XuLyIn(report, congty);
        }

        public frmBaoCaorpt(Entities.BCChiTietBanHangTheoHangHoa[] bc, string tenkho, string loaihoadon, DateTime tungay, DateTime denngay, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCChiTietBanHangTheoHangHoa";
            obj = bc;
            this.tenkho = tenkho;
            this.tungay = tungay;
            this.denngay = denngay;
            try
            {
                XuLy(bc, tenkho, loaihoadon, tungay, denngay, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCChiTietBanHangTheoHangHoa[] bc, string tenkho, string loaihoadon, DateTime tungay, DateTime denngay, string path, string hanhdong)
        {
            Entities.CongTy congty = CongTy();
            if (congty.MaCongTy.Length != 0)
                bc[0].LoGo = congty.Image; lblTitle.Text = "Báo Cáo Chi Tiết Bán Hàng Theo Hàng Hóa";

            rptViewer = new CrystalReportViewer();
            GUI.BaoCao.Report.rptBCChiTietBanHangTheoHANGHOA report = new GUI.BaoCao.Report.rptBCChiTietBanHangTheoHANGHOA();
            report.SetDataSource(bc);
            try
            {
                report.SetParameterValue("NgayTao", Entitystatic.date.ToString("dd/MM/yyyy"));
            }
            catch
            {
            }
            report.SetParameterValue("TenCongTy", congty.TenCongTy);
            report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
            report.SetParameterValue("DienThoai", congty.DienThoai);
            report.SetParameterValue("FaxCongTy", congty.Fax);
            report.SetParameterValue("Web", congty.Website);
            report.SetParameterValue("Email", congty.Email);
            report.SetParameterValue("TenBaoCao", "Báo Cáo Chi Tiết Bán Hàng Theo Hàng Hóa".ToUpper());
            report.SetParameterValue("TenKho", tenkho);
            report.SetParameterValue("TuNgay", tungay.ToString("dd/MM/yyyy"));
            report.SetParameterValue("DenNgay", denngay.ToString("dd/MM/yyyy"));
            if (hanhdong == Common.Constants.Excel)
            {
                new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
            }
            else if (hanhdong == Common.Constants.Word)
            {
                new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
            }
            else if (hanhdong == Common.Constants.PDF)
            {
                new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
            }
        }
        #endregion

        #region Hóa Đơn Bán Buôn
        public frmBaoCaorpt(Entities.BCHoaDonBanBuon[] bc, Entities.KhachHang kh, Entities.HDBanBuon hdbanbuon)
        {
            InitializeComponent();
            name = "BCHoaDonBanBuon";
            obj = bc;
            obj1 = kh;
            obj2 = hdbanbuon;
            XuLy(bc, kh, hdbanbuon);
        }
        void XuLy(Entities.BCHoaDonBanBuon[] bc, Entities.KhachHang kh, Entities.HDBanBuon hdbanbuon)
        {
            try
            {
                Entities.CongTy congty = CongTy();
                if(congty.MaCongTy.Length != 0)
                bc[0].LoGo = congty.Image;
                
                lblTitle.Text = "Báo Cáo Hóa Đơn Bán Buôn";

                BaoCao.Report.rptBCHoaDonBanBuon report = new BaoCao.Report.rptBCHoaDonBanBuon();
                report.SetDataSource(bc);
                report.SetParameterValue("DienThoai2", kh.DienThoaiDD);
                report.SetParameterValue("TenKH", kh.Ten);
                report.SetParameterValue("MaSoThue", kh.MST);
                report.SetParameterValue("TheVip", hdbanbuon.GiaTriThe);
                report.SetParameterValue("TenBaoCao", "Hóa Đơn Bán Buôn".ToUpper());
                report.SetParameterValue("SoTienDaThu", double.Parse(hdbanbuon.ThanhToanNgay) + double.Parse(hdbanbuon.ThanhToanSauKhiLapPhieu));
                report.SetParameterValue("DiaChi", kh.DiaChi);
                report.SetParameterValue("HVTNguoiNhanHang", hdbanbuon.NguoiNhanHang);
                report.SetParameterValue("SoChungTuGoc", hdbanbuon.MaHDBanBuon);
                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        public frmBaoCaorpt(Entities.BCHoaDonBanBuon[] bc, Entities.KhachHang kh, Entities.HDBanBuon hdbanbuon, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCHoaDonBanBuon";
            obj = bc;
            obj1 = kh;
            obj2 = hdbanbuon;

            try
            {
                XuLy(bc, kh, hdbanbuon, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCHoaDonBanBuon[] bc, Entities.KhachHang kh, Entities.HDBanBuon hdbanbuon, string path, string hanhdong)
        {

            try
            {
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Hóa Đơn Bán Buôn";

                BaoCao.Report.rptBCHoaDonBanBuon report = new BaoCao.Report.rptBCHoaDonBanBuon();
                report.SetDataSource(bc);
                try
                {
                    report.SetParameterValue("NgayTao", Entitystatic.date.ToString("dd/MM/yyyy"));
                }
                catch
                {
                }
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);

                report.SetParameterValue("DienThoai2", kh.DienThoaiDD);
                report.SetParameterValue("TenKH", kh.Ten);
                report.SetParameterValue("MaSoThue", kh.MST);
                report.SetParameterValue("TheVip", hdbanbuon.GiaTriThe);
                report.SetParameterValue("TenBaoCao", "Hóa Đơn Bán Buôn".ToUpper());
                report.SetParameterValue("SoTienDaThu", double.Parse(hdbanbuon.ThanhToanNgay) + double.Parse(hdbanbuon.ThanhToanSauKhiLapPhieu));
                report.SetParameterValue("DiaChi", kh.DiaChi);
                report.SetParameterValue("HVTNguoiNhanHang", hdbanbuon.NguoiNhanHang);
                report.SetParameterValue("SoChungTuGoc", hdbanbuon.MaHDBanBuon);
                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }
        #endregion

        #region Hóa đơn bán lẻ
        public frmBaoCaorpt(Entities.BCHDBanLe[] bc, Entities.HDBanLe hdbanle)
        {
            InitializeComponent();
            name = "BCHDBanLe";
            obj = bc;
            obj1 = hdbanle;
            XuLy(bc, hdbanle);
        }
        void XuLy(Entities.BCHDBanLe[] bc, Entities.HDBanLe hdbanle)
        {
            try
            {
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Hóa Đơn Bán Lẻ";
                date = Entitystatic.date;

                BaoCao.Report.rptBCHDBanHang report = new BaoCao.Report.rptBCHDBanHang();
                report.SetDataSource(bc);
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("TenBaoCao", "Hóa đơn bán lẻ".ToUpper());
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("DiaChi", congty.DiaChi);
                report.SetParameterValue("Date", date.ToString("dd/MM/yyyy") + "  Giờ: " + date.ToShortTimeString());
                report.SetParameterValue("GTGT", Common.Utilities.FormatMoney(hdbanle.ThueGTGT));
                report.SetParameterValue("ChietKhau", Common.Utilities.FormatMoney(hdbanle.ChietKhau));
                report.SetParameterValue("GiaTriThe", Common.Utilities.FormatMoney(hdbanle.GiaTriThe));
                report.SetParameterValue("VietBangChu", new ChuyenDoi().Convert(String.Format("{0:0}", double.Parse(hdbanle.TongTienThanhToan)).ToString().Trim(), ',', "phẩy"));
                report.SetParameterValue("TenNhanVien", hdbanle.TenNhanVien);
                report.SetParameterValue("Footer", "Hẹn gặp lại quý khách");
                if (Print(report))
                {
                    kiemtra = true;
                    rptViewer.ReportSource = report;
                    rptViewer.Show();
                }
            }
            catch
            {
            }
        }
        public frmBaoCaorpt(Entities.BCHDBanLe[] bc, Entities.HDBanLe hdbanle, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCHDBanLe";
            obj = bc;
            obj1 = hdbanle;
            try
            {
                XuLy(bc, hdbanle, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCHDBanLe[] bc, Entities.HDBanLe hdbanle, string path, string hanhdong)
        {
            try
            {
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Hóa Đơn Bán Lẻ";
                date = Entitystatic.date;

                BaoCao.Report.rptBCHDBanHang report = new BaoCao.Report.rptBCHDBanHang();
                report.SetDataSource(bc);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("DiaChi", congty.DiaChi);
                report.SetParameterValue("Date", hdbanle.NgayLap.ToString("dd/MM/yyyy"));
                report.SetParameterValue("GTGT", Common.Utilities.FormatMoney(hdbanle.ThueGTGT));
                report.SetParameterValue("ChietKhau", Common.Utilities.FormatMoney(hdbanle.ChietKhau));
                report.SetParameterValue("GiaTriThe", Common.Utilities.FormatMoney(hdbanle.GiaTriThe));
                report.SetParameterValue("VietBangChu", new ChuyenDoi().Convert(String.Format("{0:0}", Convert.ToDouble(hdbanle.TongTienThanhToan)).ToString().Trim(), ',', "phẩy"));
                report.SetParameterValue("TenBaoCao", "Hóa Đơn Bán Lẻ".ToUpper());
                report.SetParameterValue("Footer", "Hẹn gặp lại quý khách");

                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }

        #endregion

        #region trả lại nhà cung cấp
        public frmBaoCaorpt(Entities.BCTraLaiNCC[] bc, Entities.TraLaiNCC tralaincc, Entities.NhaCungCap ncc)
        {
            InitializeComponent();
            name = "BCTraLaiNCC";
            obj = bc;
            obj1 = tralaincc;
            obj2 = ncc;
            XuLy(bc, tralaincc, ncc);
        }
        void XuLy(Entities.BCTraLaiNCC[] bc, Entities.TraLaiNCC tralaincc, Entities.NhaCungCap ncc)
        {
            try
            {
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Phiếu Trả Lại Nhà Cung Cấp";

                BaoCao.Report.rptTraLaiNCC report = new BaoCao.Report.rptTraLaiNCC();
                report.SetDataSource(bc);
                report.SetParameterValue("DT", ncc.DienThoai);
                report.SetParameterValue("DiaChi", ncc.DiaChi);
                report.SetParameterValue("TenNCC", ncc.TenNhaCungCap);
                report.SetParameterValue("GhiChu", tralaincc.GhiChu);
                report.SetParameterValue("MaHoaDon", tralaincc.MaHDTraLaiNCC);
                report.SetParameterValue("TenBaoCao", "Phiếu Trả Lại Nhà Cung Cấp".ToUpper());
                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        public frmBaoCaorpt(Entities.BCTraLaiNCC[] bc, Entities.TraLaiNCC tralaincc, Entities.NhaCungCap ncc, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCTraLaiNCC";
            obj = bc;
            obj1 = tralaincc;
            obj2 = ncc;
            try
            {
                XuLy(bc, tralaincc, ncc, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCTraLaiNCC[] bc, Entities.TraLaiNCC tralaincc, Entities.NhaCungCap ncc, string path, string hanhdong)
        {
            try
            {
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Phiếu Trả Lại Nhà Cung Cấp";

                BaoCao.Report.rptTraLaiNCC report = new BaoCao.Report.rptTraLaiNCC();
                report.SetDataSource(bc);
                try
                {
                    report.SetParameterValue("NgayTao", Entitystatic.date.ToString("dd/MM/yyyy"));
                }
                catch
                {
                }
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);
                report.SetParameterValue("DT", ncc.DienThoai);
                report.SetParameterValue("DiaChi", ncc.DiaChi);
                report.SetParameterValue("TenNCC", ncc.TenNhaCungCap);
                report.SetParameterValue("GhiChu", tralaincc.GhiChu);
                report.SetParameterValue("MaHoaDon", tralaincc.MaHDTraLaiNCC);
                report.SetParameterValue("TenBaoCao", "Phiếu Trả Lại Nhà Cung Cấp".ToUpper());

                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }

        #endregion

        #region Tổng hợp công nợ nhà cung cấp
        public frmBaoCaorpt(Entities.BCTongHopCongNoNCC[] bc, string tenkho, DateTime tungay, DateTime denngay)
        {
            InitializeComponent();
            name = "BCTongHopCongNoNCC";
            obj = bc;
            this.tenkho = tenkho;
            this.tungay = tungay;
            this.denngay = denngay;
            try
            {
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Tổng Hợp Công Nợ Nhà Cung Cấp";
                rptViewer = new CrystalReportViewer();
                BaoCao.Report.rptBCTongHopCongNoNCC report = new BaoCao.Report.rptBCTongHopCongNoNCC();
                report.SetDataSource(bc);
                report.SetParameterValue("TenKho", tenkho);
                report.SetParameterValue("TuNgay", tungay.ToString("dd/MM/yyyy"));
                report.SetParameterValue("DenNgay", denngay.ToString("dd/MM/yyyy"));
                report.SetParameterValue("TenBaoCao", "Báo Cáo Tổng Hợp Công Nợ Nhà Cung Cấp".ToUpper());

                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        public frmBaoCaorpt(Entities.BCTongHopCongNoNCC[] bc, string tenkho, DateTime tungay, DateTime denngay, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCTongHopCongNoNCC";
            obj = bc;
            this.tungay = tungay;
            this.denngay = denngay;
            try
            {
                XuLy(bc, tenkho, tungay, denngay, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCTongHopCongNoNCC[] bc, string tenkho, DateTime tungay, DateTime denngay, string path, string hanhdong)
        {
            try
            {
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Tổng Hợp Công Nợ Nhà Cung Cấp";
                rptViewer = new CrystalReportViewer();
                BaoCao.Report.rptBCTongHopCongNoNCC report = new BaoCao.Report.rptBCTongHopCongNoNCC();
                report.SetDataSource(bc);
                try
                {
                    report.SetParameterValue("NgayTao", Common.StaticVariable.InterfaceObject.SelectDate().ToString("dd/MM/yyyy"));
                }
                catch
                {
                }
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);

                report.SetParameterValue("TenKho", tenkho);
                report.SetParameterValue("TuNgay", tungay.ToString("dd/MM/yyyy"));
                report.SetParameterValue("DenNgay", denngay.ToString("dd/MM/yyyy"));
                report.SetParameterValue("TenBaoCao", "Báo Cáo Tổng Hợp Công Nợ Nhà Cung Cấp".ToUpper());

                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }

        #endregion

        #region báo cáo xuất hủy hàng hóa
        public frmBaoCaorpt(Entities.BCXuatHuyHangHoa[] bc, string tenkho, DateTime tungay, DateTime denngay)
        {
            InitializeComponent();
            name = "BCXuatHuyHangHoa";
            obj = bc;
            this.tenkho = tenkho;
            this.tungay = tungay;
            this.denngay = denngay;
            try
            {
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Xuất Hủy Hàng Hóa";
                rptViewer = new CrystalReportViewer();
                BaoCao.Report.rptBCXuatHuyHangHoa report = new BaoCao.Report.rptBCXuatHuyHangHoa();
                report.SetDataSource(bc);
                report.SetParameterValue("TenKho", tenkho);
                report.SetParameterValue("TuNgay", tungay.ToString("dd/MM/yyyy"));
                report.SetParameterValue("DenNgay", denngay.ToString("dd/MM/yyyy"));
                report.SetParameterValue("TenBaoCao", "Báo Cáo Xuất Hủy Hàng Hóa".ToUpper());

                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        public frmBaoCaorpt(Entities.BCXuatHuyHangHoa[] bc, string tenkho, DateTime tungay, DateTime denngay, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCXuatHuyHangHoa";
            obj = bc;
            this.tungay = tungay;
            this.denngay = denngay;
            try
            {
                XuLy(bc, tenkho, tungay, denngay, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCXuatHuyHangHoa[] bc, string tenkho, DateTime tungay, DateTime denngay, string path, string hanhdong)
        {
            try
            {
                Entities.CongTy congty = CongTy();
                if (congty.MaCongTy.Length != 0)
                    bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Xuất Hủy Hàng Hóa";
                rptViewer = new CrystalReportViewer();
                BaoCao.Report.rptBCXuatHuyHangHoa report = new BaoCao.Report.rptBCXuatHuyHangHoa();
                report.SetDataSource(bc);
                try
                {
                    report.SetParameterValue("NgayTao", Common.StaticVariable.InterfaceObject.SelectDate().ToString("dd/MM/yyyy"));
                }
                catch
                {
                }
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);

                report.SetParameterValue("TenKho", tenkho);
                report.SetParameterValue("TuNgay", tungay.ToString("dd/MM/yyyy"));
                report.SetParameterValue("DenNgay", denngay.ToString("dd/MM/yyyy"));
                report.SetParameterValue("TenBaoCao", "Báo Cáo Xuất Hủy Hàng Hóa".ToUpper());

                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }

        #endregion

        #region loivt
        #region Phiếu Thu

        public frmBaoCaorpt(Entities.PhieuThu phieuthu)
        {
            InitializeComponent();
            name = "BCPhieuThu";
            obj2 = phieuthu;
            XuLy(phieuthu);
        }
        public frmBaoCaorpt(Entities.PhieuThu phieuthu, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCPhieuThu";
            obj2 = phieuthu;

            try
            {
                XuLy(phieuthu, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.PhieuThu phieuthu)
        {
            try
            {
                Entities.CongTy congty = CongTy();
                lblTitle.Text = "Báo Cáo Phiếu Thu";

                BaoCao.Report.rptBCPhieuThu report = new BaoCao.Report.rptBCPhieuThu();
                report.SetParameterValue("TenBaoCao", "Phiếu Thu".ToUpper());
                report.SetParameterValue("QuyenSo", "");
                report.SetParameterValue("NoTK", phieuthu.NoTaiKhoan);
                report.SetParameterValue("CoTK", phieuthu.CoTaiKhoan);
                report.SetParameterValue("HVTNguoiNopTien", phieuthu.NguoiNopTien);
                report.SetParameterValue("DiaChi", phieuthu.DiaChi);
                report.SetParameterValue("LyDoThu", phieuthu.GhiChu);
                report.SetParameterValue("SoTien", Common.Utilities.FormatMoney(phieuthu.TongTienThanhToan));
                report.SetParameterValue("VietBangChu", new ChuyenDoi().Convert(String.Format("{0:0}", Convert.ToDouble(phieuthu.TongTienThanhToan)).ToString().Trim(), ',', "phẩy"));
                report.SetParameterValue("KemTheo", "");
                report.SetParameterValue("ChungTuGoc", phieuthu.MaPhieuThu);
                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        void XuLy(Entities.PhieuThu phieuthu, string path, string hanhdong)
        {

            try
            {
                Entities.CongTy congty = CongTy();
                lblTitle.Text = "Báo Cáo Phiếu Thu";

                BaoCao.Report.rptBCPhieuThu report = new BaoCao.Report.rptBCPhieuThu();


                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);
                report.SetParameterValue("TenBaoCao", "Phiếu Thu".ToUpper());
                report.SetParameterValue("QuyenSo", "");
                report.SetParameterValue("NoTK", phieuthu.NoTaiKhoan);
                report.SetParameterValue("CoTK", phieuthu.CoTaiKhoan);
                report.SetParameterValue("HVTNguoiNopTien", phieuthu.NguoiNopTien);
                report.SetParameterValue("DiaChi", phieuthu.DiaChi);
                report.SetParameterValue("LyDoThu", phieuthu.GhiChu);
                report.SetParameterValue("SoTien", Common.Utilities.FormatMoney(phieuthu.TongTienThanhToan));
                report.SetParameterValue("VietBangChu", new ChuyenDoi().Convert(String.Format("{0:0}", Convert.ToDouble(phieuthu.TongTienThanhToan)).ToString().Trim(), ',', "phẩy"));
                report.SetParameterValue("KemTheo", "");
                report.SetParameterValue("ChungTuGoc", phieuthu.MaPhieuThu);
                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }

        #endregion

        #region Phiếu Chi

        public frmBaoCaorpt(Entities.PhieuChi phieuchi)
        {
            InitializeComponent();
            name = "PhieuChi";
            obj1 = phieuchi;

            try
            {
                Entities.CongTy congty = CongTy();
                lblTitle.Text = "Báo Cáo Phiếu Chi";

                BaoCao.Report.rptBCPhieuChi report = new BaoCao.Report.rptBCPhieuChi();
                report.SetParameterValue("TenBaoCao", "Phiếu Chi".ToUpper());
                report.SetParameterValue("QuyenSo", "");
                report.SetParameterValue("NoTK", phieuchi.NoTaiKhoan);
                report.SetParameterValue("CoTK", phieuchi.CoTaiKhoan);
                report.SetParameterValue("HVTNguoiNhanTien", phieuchi.NguoiNhanTien);
                report.SetParameterValue("DiaChi", phieuchi.DiaChi);
                report.SetParameterValue("LyDoChi", phieuchi.GhiChu);
                report.SetParameterValue("SoTien", Common.Utilities.FormatMoney(phieuchi.TongTienThanhToan));
                report.SetParameterValue("VietBangChu", new ChuyenDoi().Convert(String.Format("{0:0}", Convert.ToDouble(phieuchi.TongTienThanhToan)).ToString().Trim(), ',', "phẩy"));
                report.SetParameterValue("KemTheo", "");
                report.SetParameterValue("ChungTuGoc", phieuchi.MaPhieuChi);

                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        public frmBaoCaorpt(Entities.PhieuChi phieuchi, string path, string hanhdong)
        {
            InitializeComponent();
            name = "PhieuChi";
            obj1 = phieuchi;

            try
            {
                XuLy(phieuchi, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.PhieuChi phieuchi, string path, string hanhdong)
        {
            try
            {
                Entities.CongTy congty = CongTy();
                lblTitle.Text = "Báo Cáo Phiếu Chi";

                BaoCao.Report.rptBCPhieuChi report = new BaoCao.Report.rptBCPhieuChi();
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);
                report.SetParameterValue("TenBaoCao", "Phiếu Chi".ToUpper());
                report.SetParameterValue("QuyenSo", "");
                report.SetParameterValue("NoTK", phieuchi.NoTaiKhoan);
                report.SetParameterValue("CoTK", phieuchi.CoTaiKhoan);
                report.SetParameterValue("HVTNguoiNhanTien", phieuchi.NguoiNhanTien);
                report.SetParameterValue("DiaChi", phieuchi.DiaChi);
                report.SetParameterValue("LyDoChi", phieuchi.GhiChu);
                report.SetParameterValue("SoTien", Common.Utilities.FormatMoney(phieuchi.TongTienThanhToan));
                report.SetParameterValue("VietBangChu", new ChuyenDoi().Convert(String.Format("{0:0}", Convert.ToDouble(phieuchi.TongTienThanhToan)).ToString().Trim(), ',', "phẩy"));
                report.SetParameterValue("KemTheo", "");
                report.SetParameterValue("ChungTuGoc", phieuchi.MaPhieuChi);

                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }

        #endregion

        #region Phiếu thanh toán khách hàng phiếu chi
        public frmBaoCaorpt(Entities.BCPhieuThanhToanKhachHangPHIEUCHI[] bc, Entities.KhachHang kh, Entities.PhieuTTCuaKH phieuthanhtoankh)
        {
            InitializeComponent();
            name = "BCPhieuThanhToanKhachHangPHIEUCHI";
            obj = bc;
            obj1 = kh;
            obj2 = phieuthanhtoankh;

            try
            {
                Entities.CongTy congty = CongTy();
                bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Phiếu Thanh Toán Khách Hàng - Trả Lại Khách Hàng";
                rptViewer = new CrystalReportViewer();
                string sochungtugoc = "";
                foreach (Entities.BCPhieuThanhToanKhachHangPHIEUCHI item in bc)
                {
                    sochungtugoc += item.SoHD + ", ";
                }
                BaoCao.Report.rptBCPhieuThanhToanKhachHangPHIEUCHI report = new BaoCao.Report.rptBCPhieuThanhToanKhachHangPHIEUCHI();
                report.SetDataSource(bc);
                report.SetParameterValue("DienThoai2", kh.DienThoaiDD);
                report.SetParameterValue("MaSoThue", kh.MST);
                report.SetParameterValue("MaKH", kh.MaKhachHang);
                report.SetParameterValue("DienGiai", phieuthanhtoankh.GhiChu);
                report.SetParameterValue("TenBaoCao", "Phiếu Thanh Toán khách Hàng (Phiếu Chi)".ToUpper());
                report.SetParameterValue("TenKH", kh.Ten);
                report.SetParameterValue("DiaChi", kh.DiaChi);
                report.SetParameterValue("NguoiNhanTien", phieuthanhtoankh.NguoiNop);
                report.SetParameterValue("MaPhieu", phieuthanhtoankh.MaPhieuTTCuaKH);
                report.SetParameterValue("SoChungTuGoc", sochungtugoc);
                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        public frmBaoCaorpt(Entities.BCPhieuThanhToanKhachHangPHIEUCHI[] bc, Entities.KhachHang kh, Entities.PhieuTTCuaKH phieuthanhtoankh, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCPhieuThanhToanKhachHangPHIEUCHI";
            obj = bc;
            obj1 = kh;
            obj2 = phieuthanhtoankh;

            try
            {
                XuLy(bc, kh, phieuthanhtoankh, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCPhieuThanhToanKhachHangPHIEUCHI[] bc, Entities.KhachHang kh, Entities.PhieuTTCuaKH phieuthanhtoankh, string path, string hanhdong)
        {
            try
            {
                Entities.CongTy congty = CongTy();
                bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Phiếu Thanh Toán Khách Hàng - Trả Lại Khách Hàng";
                rptViewer = new CrystalReportViewer();
                string sochungtugoc = "";
                foreach (Entities.BCPhieuThanhToanKhachHangPHIEUCHI item in bc)
                {
                    sochungtugoc += item.SoHD + ", ";
                }
                BaoCao.Report.rptBCPhieuThanhToanKhachHangPHIEUCHI report = new BaoCao.Report.rptBCPhieuThanhToanKhachHangPHIEUCHI();
                report.SetDataSource(bc);
                try
                {
                    report.SetParameterValue("NgayTao", Entitystatic.date.ToString("dd/MM/yyyy"));
                }
                catch
                {
                }
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);
                report.SetParameterValue("DienThoai2", kh.DienThoaiDD);
                report.SetParameterValue("MaSoThue", kh.MST);
                report.SetParameterValue("MaKH", kh.MaKhachHang);
                report.SetParameterValue("DienGiai", phieuthanhtoankh.GhiChu);
                report.SetParameterValue("TenBaoCao", "Phiếu Thanh Toán khách Hàng (Phiếu Chi)".ToUpper());
                report.SetParameterValue("TenKH", kh.Ten);
                report.SetParameterValue("DiaChi", kh.DiaChi);
                report.SetParameterValue("NguoiNhanTien", phieuthanhtoankh.NguoiNop);
                report.SetParameterValue("MaPhieu", phieuthanhtoankh.MaPhieuTTCuaKH);
                report.SetParameterValue("SoChungTuGoc", sochungtugoc);
                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }
        #endregion
        #region Phiếu thanh toán khách hàng phiếu thu
        public frmBaoCaorpt(Entities.BCPhieuThanhToanKhachHangPHIEUTHU[] bc, Entities.KhachHang kh, Entities.PhieuTTCuaKH phieuthanhtoankh)
        {
            InitializeComponent();
            name = "BCPhieuThanhToanKhachHangPHIEUTHU";
            obj = bc;
            obj1 = kh;
            obj2 = phieuthanhtoankh;

            try
            {
                Entities.CongTy congty = CongTy();
                bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Phiếu Thanh Toán Khách Hàng - Thanh Toán Hóa Đơn";
                rptViewer = new CrystalReportViewer();
                string sochungtugoc = "";
                foreach (Entities.BCPhieuThanhToanKhachHangPHIEUTHU item in bc)
                {
                    sochungtugoc += item.SoHoaDon + ", ";
                }
                BaoCao.Report.rptBCPhieuThanhToanKhachHangPHIEUTHU report = new BaoCao.Report.rptBCPhieuThanhToanKhachHangPHIEUTHU();
                report.SetDataSource(bc);
                report.SetParameterValue("DienThoai2", kh.DienThoaiDD);
                report.SetParameterValue("MaSoThue", kh.MST);
                report.SetParameterValue("MaKH", kh.MaKhachHang);
                report.SetParameterValue("DienGiai", phieuthanhtoankh.GhiChu);
                report.SetParameterValue("TenBaoCao", "Phiếu Thanh Toán khách Hàng (Phiếu Thu)".ToUpper());
                report.SetParameterValue("TenKH", kh.Ten);
                report.SetParameterValue("DiaChi", kh.DiaChi);
                report.SetParameterValue("NguoiNopTien", phieuthanhtoankh.NguoiNop);
                report.SetParameterValue("MaPhieu", phieuthanhtoankh.MaPhieuTTCuaKH);
                report.SetParameterValue("SoChungTuGoc", sochungtugoc);
                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        public frmBaoCaorpt(Entities.BCPhieuThanhToanKhachHangPHIEUTHU[] bc, Entities.KhachHang kh, Entities.PhieuTTCuaKH phieuthanhtoankh, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCPhieuThanhToanKhachHangPHIEUTHU";
            obj = bc;
            obj1 = kh;
            obj2 = phieuthanhtoankh;

            try
            {
                XuLy(bc, kh, phieuthanhtoankh, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCPhieuThanhToanKhachHangPHIEUTHU[] bc, Entities.KhachHang kh, Entities.PhieuTTCuaKH phieuthanhtoankh, string path, string hanhdong)
        {

            try
            {
                string sochungtugoc = "";
                foreach (Entities.BCPhieuThanhToanKhachHangPHIEUTHU item in bc)
                {
                    sochungtugoc += item.SoHoaDon + ", ";
                }
                Entities.CongTy congty = CongTy(); 
                bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Phiếu Thanh Toán Khách Hàng - Thanh Toán Hóa Đơn";
                rptViewer = new CrystalReportViewer();

                BaoCao.Report.rptBCPhieuThanhToanKhachHangPHIEUTHU report = new BaoCao.Report.rptBCPhieuThanhToanKhachHangPHIEUTHU();
                report.SetDataSource(bc);
                try
                {
                    report.SetParameterValue("NgayTao", Entitystatic.date.ToString("dd/MM/yyyy"));
                }
                catch
                {
                }
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);
                report.SetParameterValue("DienThoai2", kh.DienThoaiDD);
                report.SetParameterValue("MaSoThue", kh.MST);
                report.SetParameterValue("MaKH", kh.MaKhachHang);
                report.SetParameterValue("DienGiai", phieuthanhtoankh.GhiChu);
                report.SetParameterValue("TenBaoCao", "Phiếu Thanh Toán khách Hàng (Phiếu Thu)".ToUpper());
                report.SetParameterValue("TenKH", kh.Ten);
                report.SetParameterValue("DiaChi", kh.DiaChi);
                report.SetParameterValue("NguoiNopTien", phieuthanhtoankh.NguoiNop);
                report.SetParameterValue("MaPhieu", phieuthanhtoankh.MaPhieuTTCuaKH);
                report.SetParameterValue("SoChungTuGoc", sochungtugoc);
                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }
        #endregion

        #region Phiếu thanh toán nhà cung cấp phiếu chi
        public frmBaoCaorpt(Entities.BCPhieuThanhToanNCCPHIEUCHI[] bc, Entities.NhaCungCap ncc, Entities.PhieuTTNCC phieuthanhtoanncc)
        {
            InitializeComponent();
            name = "BCPhieuThanhToanNCCPHIEUCHI";
            obj = bc;
            obj1 = ncc;
            obj2 = phieuthanhtoanncc;

            try
            {
                string sochungtugoc = "";
                foreach (Entities.BCPhieuThanhToanNCCPHIEUCHI item in bc)
                {
                    sochungtugoc += item.SoHD + ", ";
                }
                Entities.CongTy congty = CongTy();  
                bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Phiếu Thanh Toán Nhà Cung Cấp - Thanh Toán Hóa Đơn";
                rptViewer = new CrystalReportViewer();
               
                BaoCao.Report.rptBCPhieuThanhToanNCCPHIEUCHI report = new BaoCao.Report.rptBCPhieuThanhToanNCCPHIEUCHI();
                report.SetDataSource(bc);
                report.SetParameterValue("DienThoai2", ncc.DienThoai);
                report.SetParameterValue("MaSoThue", ncc.MaSoThue);
                report.SetParameterValue("MaNCC", ncc.MaNhaCungCap);
                report.SetParameterValue("DienGiai", phieuthanhtoanncc.GhiChu);
                report.SetParameterValue("TenBaoCao", "Phiếu Thanh Toán Nhà Cung Cấp (Phiếu Chi)".ToUpper());
                report.SetParameterValue("TenNCC", ncc.TenNhaCungCap);
                report.SetParameterValue("DiaChi", ncc.DiaChi);
                report.SetParameterValue("NguoiNhanTien", phieuthanhtoanncc.Nguoinhan);
                report.SetParameterValue("MaPhieu", phieuthanhtoanncc.MaPhieuTTNCC);
                report.SetParameterValue("SoChungTuGoc", sochungtugoc);
                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        public frmBaoCaorpt(Entities.BCPhieuThanhToanNCCPHIEUCHI[] bc, Entities.NhaCungCap ncc, Entities.PhieuTTNCC phieuthanhtoanncc, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCPhieuThanhToanNCCPHIEUCHI";
            obj = bc;
            obj1 = ncc;
            obj2 = phieuthanhtoanncc;

            try
            {
                XuLy(bc, ncc, phieuthanhtoanncc, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCPhieuThanhToanNCCPHIEUCHI[] bc, Entities.NhaCungCap ncc, Entities.PhieuTTNCC phieuthanhtoanncc, string path, string hanhdong)
        {
            try
            {
                string sochungtugoc = "";
                foreach (Entities.BCPhieuThanhToanNCCPHIEUCHI item in bc)
                {
                    sochungtugoc += item.SoHD + ", ";
                }
                Entities.CongTy congty = CongTy();
                bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Phiếu Thanh Toán Nhà Cung Cấp - Thanh Toán Hóa Đơn";
                rptViewer = new CrystalReportViewer();

                BaoCao.Report.rptBCPhieuThanhToanNCCPHIEUCHI report = new BaoCao.Report.rptBCPhieuThanhToanNCCPHIEUCHI();
                report.SetDataSource(bc);
                try
                {
                    report.SetParameterValue("NgayTao", Entitystatic.date.ToString("dd/MM/yyyy"));
                }
                catch
                {
                }
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);
                report.SetParameterValue("DienThoai2", ncc.DienThoai);
                report.SetParameterValue("MaSoThue", ncc.MaSoThue);
                report.SetParameterValue("MaNCC", ncc.MaNhaCungCap);
                report.SetParameterValue("DienGiai", phieuthanhtoanncc.GhiChu);
                report.SetParameterValue("TenBaoCao", "Phiếu Thanh Toán Nhà Cung Cấp (Phiếu Chi)".ToUpper());
                report.SetParameterValue("TenNCC", ncc.TenNhaCungCap);
                report.SetParameterValue("DiaChi", ncc.DiaChi);
                report.SetParameterValue("NguoiNhanTien", phieuthanhtoanncc.Nguoinhan);
                report.SetParameterValue("MaPhieu", phieuthanhtoanncc.MaPhieuTTNCC);
                report.SetParameterValue("SoChungTuGoc", sochungtugoc);
                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }
        #endregion
        #region Phiếu thanh toán nhà cung cấp phiếu thu
        public frmBaoCaorpt(Entities.BCPhieuThanhToanNCCPHIEUTHU[] bc, Entities.NhaCungCap ncc, Entities.PhieuTTNCC phieuthanhtoanncc)
        {
            InitializeComponent();
            name = "BCPhieuThanhToanNCCPHIEUTHU";
            obj = bc;
            obj1 = ncc;
            obj2 = phieuthanhtoanncc;

            try
            {
                string sochungtugoc = "";
                foreach (Entities.BCPhieuThanhToanNCCPHIEUTHU item in bc)
                {
                    sochungtugoc += item.SoHD + ", ";
                }
                Entities.CongTy congty = CongTy(); 
                bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Phiếu Thanh Toán Khách Hàng - Trả Lại Hàng";
                rptViewer = new CrystalReportViewer();
                BaoCao.Report.rptBCPhieuThanhToanNCCPHIEUCHI report = new BaoCao.Report.rptBCPhieuThanhToanNCCPHIEUCHI();
                report.SetDataSource(bc);
                report.SetParameterValue("DienThoai2", ncc.DienThoai);
                report.SetParameterValue("MaSoThue", ncc.MaSoThue);
                report.SetParameterValue("MaNCC", ncc.MaNhaCungCap);
                report.SetParameterValue("DienGiai", phieuthanhtoanncc.GhiChu);
                report.SetParameterValue("TenBaoCao", "Phiếu Thanh Toán Nhà Cung Cấp (Phiếu Chi)".ToUpper());
                report.SetParameterValue("TenNCC", ncc.TenNhaCungCap);
                report.SetParameterValue("DiaChi", ncc.DiaChi);
                report.SetParameterValue("NguoiNhanTien", phieuthanhtoanncc.Nguoinhan);
                report.SetParameterValue("MaPhieu", phieuthanhtoanncc.MaPhieuTTNCC);
                report.SetParameterValue("SoChungTuGoc", sochungtugoc);

                XuLyIn(report, congty);
            }
            catch
            {
            }
        }
        public frmBaoCaorpt(Entities.BCPhieuThanhToanNCCPHIEUTHU[] bc, Entities.NhaCungCap ncc, Entities.PhieuTTNCC phieuthanhtoanncc, string path, string hanhdong)
        {
            InitializeComponent();
            name = "BCPhieuThanhToanNCCPHIEUTHU";
            obj = bc;
            obj1 = ncc;
            obj2 = phieuthanhtoanncc;

            try
            {
                XuLy(bc, ncc, phieuthanhtoanncc, path, hanhdong);
            }
            catch
            {
            }
        }
        void XuLy(Entities.BCPhieuThanhToanNCCPHIEUTHU[] bc, Entities.NhaCungCap ncc, Entities.PhieuTTNCC phieuthanhtoanncc, string path, string hanhdong)
        {
            try
            {
                string sochungtugoc = "";
                foreach (Entities.BCPhieuThanhToanNCCPHIEUTHU item in bc)
                {
                    sochungtugoc += item.SoHD + ", ";
                }
                Entities.CongTy congty = CongTy();
                bc[0].LoGo = congty.Image;
                lblTitle.Text = "Báo Cáo Phiếu Thanh Toán Khách Hàng - Trả Lại Hàng";
                rptViewer = new CrystalReportViewer();
                BaoCao.Report.rptBCPhieuThanhToanNCCPHIEUCHI report = new BaoCao.Report.rptBCPhieuThanhToanNCCPHIEUCHI();
                report.SetDataSource(bc);
                try
                {
                    report.SetParameterValue("NgayTao", Entitystatic.date.ToString("dd/MM/yyyy"));
                }
                catch
                {
                }
                report.SetParameterValue("TenCongTy", congty.TenCongTy);
                report.SetParameterValue("DiaChiCongTy", congty.DiaChi);
                report.SetParameterValue("DienThoai", congty.DienThoai);
                report.SetParameterValue("FaxCongTy", congty.Fax);
                report.SetParameterValue("Web", congty.Website);
                report.SetParameterValue("Email", congty.Email);
                report.SetParameterValue("DienThoai2", ncc.DienThoai);
                report.SetParameterValue("MaSoThue", ncc.MaSoThue);
                report.SetParameterValue("MaNCC", ncc.MaNhaCungCap);
                report.SetParameterValue("DienGiai", phieuthanhtoanncc.GhiChu);
                report.SetParameterValue("TenBaoCao", "Phiếu Thanh Toán Nhà Cung Cấp (Phiếu Chi)".ToUpper());
                report.SetParameterValue("TenNCC", ncc.TenNhaCungCap);
                report.SetParameterValue("DiaChi", ncc.DiaChi);
                report.SetParameterValue("NguoiNhanTien", phieuthanhtoanncc.Nguoinhan);
                report.SetParameterValue("MaPhieu", phieuthanhtoanncc.MaPhieuTTNCC);
                report.SetParameterValue("SoChungTuGoc", sochungtugoc);

                if (hanhdong == Common.Constants.Excel)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.Excel);
                }
                else if (hanhdong == Common.Constants.Word)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.WordForWindows);
                }
                else if (hanhdong == Common.Constants.PDF)
                {
                    new GUI.BaoCao.ExportCrystalReport().Export(report, path, BaoCao.ExportCrystalReport.TypeBC.PortableDocFormat);
                }
            }
            catch
            {
            }
        }
        #endregion

        #endregion
  
        #region In
        void In()
        {
            switch (name)
            {
                case "BCHDBanLe":
                    {
                        Entities.BCHDBanLe[] bc = (Entities.BCHDBanLe[])obj;
                        Entities.HDBanLe hdbanle = (Entities.HDBanLe)obj1;
                        XuLy(bc, hdbanle);
                        break;
                    }
                case "BCHoaDonBanBuon":
                    {
                        Entities.BCHoaDonBanBuon[] bc = (Entities.BCHoaDonBanBuon[])obj;
                        Entities.KhachHang kh = (Entities.KhachHang)obj1;
                        Entities.HDBanBuon pt = (Entities.HDBanBuon)obj2;
                        XuLy(bc, kh, pt);
                        break;
                    }
                case "BCTraLaiNCC":
                    {
                        Entities.BCTraLaiNCC[] bc = (Entities.BCTraLaiNCC[])obj;
                        Entities.TraLaiNCC hdbanle = (Entities.TraLaiNCC)obj1;
                        Entities.NhaCungCap ncc = (Entities.NhaCungCap)obj2;
                        XuLy(bc, hdbanle, ncc);
                        break;
                    }
              
            }
        }
        #endregion

        #region Word
        void Word()
        {
            savefile = new System.Windows.Forms.SaveFileDialog();
            savefile.Filter = "Word |*.doc"; savefile.FileName = "";
            if (savefile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string hanhdong = Common.Constants.Word;
                XuLyChietXuat(hanhdong);
                MessageBox.Show("Chiết xuất thành công", Common.MSG.TieuDe);
            }
        }
        #endregion

        #region Excel
        void Excel()
        {
            savefile = new System.Windows.Forms.SaveFileDialog();
            savefile.Filter = "Excel |*.xls"; savefile.FileName = "";
            if (savefile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string hanhdong = Common.Constants.Excel;
                XuLyChietXuat(hanhdong);
                MessageBox.Show("Chiết xuất thành công", Common.MSG.TieuDe);
            }
        }
        #endregion

        #region PDF
        void PDF()
        {
            savefile = new System.Windows.Forms.SaveFileDialog();
            savefile.Filter = "PDF |*.pdf"; savefile.FileName = "";
            if (savefile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string hanhdong = Common.Constants.PDF;
                XuLyChietXuat(hanhdong);
                MessageBox.Show("Chiết xuất thành công", Common.MSG.TieuDe);
            }
        }
        #endregion

        #region Xử lý chiết xuất
        void XuLyChietXuat(string hanhdong)
        {
            switch (name)
            {
                case "BCHDBanLe":
                    {
                        Entities.BCHDBanLe[] bc = (Entities.BCHDBanLe[])obj;
                        Entities.HDBanLe hdbanle = (Entities.HDBanLe)obj1;
                        XuLy(bc, hdbanle, savefile.FileName, hanhdong);
                        break;
                    }
                case "BCHoaDonBanBuon":
                    {
                        Entities.BCHoaDonBanBuon[] bc = (Entities.BCHoaDonBanBuon[])obj;
                        Entities.KhachHang kh = (Entities.KhachHang)obj1;
                        Entities.HDBanBuon pt = (Entities.HDBanBuon)obj2;
                        XuLy(bc, kh, pt, savefile.FileName, hanhdong);
                        break;
                    }
                case "BCTraLaiNCC":
                    {
                        Entities.BCTraLaiNCC[] bc = (Entities.BCTraLaiNCC[])obj;
                        Entities.TraLaiNCC hdbanle = (Entities.TraLaiNCC)obj1;
                        Entities.NhaCungCap ncc = (Entities.NhaCungCap)obj2;
                        XuLy(bc, hdbanle, ncc, savefile.FileName, hanhdong);
                        break;
                    }
            }
        }
        #endregion

        #region Thoát
        void Thoat()
        {
            try
            {
                    this.Close();
            }
            catch
            {
            }
        }
        #endregion

        #region Event
        private void frmBaoCaorpt_Load(object sender, EventArgs e)
        {
            this.Closing +=new CancelEventHandler(frmBaoCaorpt_Closing);
            btnExcel.Click += new EventHandler(btnExcel_Click);
            btnIn.Click += new EventHandler(btnIn_Click);
            btnPDF.Click += new EventHandler(btnPDF_Click);
            btnThoat.Click += new EventHandler(btnThoat_Click);
            btnWord.Click += new EventHandler(btnWord_Click);
        }

        void btnWord_Click(object sender, EventArgs e)
        {
            Word();
        }

        void btnThoat_Click(object sender, EventArgs e)
        {
            Thoat();
        }

        void btnPDF_Click(object sender, EventArgs e)
        {
            PDF();
        }

        void btnIn_Click(object sender, EventArgs e)
        {
           In();
        }

        void btnExcel_Click(object sender, EventArgs e)
        {
            Excel();
        }

        void frmBaoCaorpt_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            try
            {
                if (!checkClose)
                    if (MessageBox.Show(Common.MSG.MSG2(), Common.MSG.TieuDe, MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                        e.Cancel = checkClose;
                    else
                        e.Cancel = !checkClose;
            }
            catch
            {
            }
        }
        #endregion

    }
}